﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Maticsoft.Web.Admin.Shopping
{
    public partial class OrderLogisticsList : System.Web.UI.Page
    {
        int OrderId, Id;
        BLL.LogisticsInfo logiBLL = new BLL.LogisticsInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString["id"], out Id);
            int.TryParse(Request.QueryString["orderid"], out OrderId);
            if (!IsPostBack)
            {
                BindList();
                GetData();
            }
        }

        protected void GetData()
        {
            if (Id > 0)
            {
                Model.LogisticsInfo logiModel = logiBLL.GetModel(Id);
                txtTitle.Text = logiModel.LogisticsName;
                txtNo.Text = logiModel.LogisticsNo;
                txtUrl.Text = logiModel.Url;
                txtSendDate.Text = logiModel.SendDate.ToString();
            }
        }

        protected void BindList()
        {
            DataSet ds = logiBLL.GetList("OrderId="+OrderId+" order by CreateTime");
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Model.LogisticsInfo logiModel = new Model.LogisticsInfo();
            logiModel.CreateTime = DateTime.Now;
            logiModel.IsActive = 1;
            if (Id > 0)
            {
                logiModel = logiBLL.GetModel(Id);
            }
            logiModel.LogisticsName = txtTitle.Text.Trim();
            logiModel.LogisticsNo = txtNo.Text.Trim();
            logiModel.Url = txtUrl.Text.Trim();
            logiModel.SendDate = DateTime.Parse(txtSendDate.Text.Trim());
            logiModel.OrderId = this.OrderId;
            if (Id > 0)
            {
                logiBLL.Update(logiModel);
            }
            else
            {
                logiBLL.Add(logiModel);
            }
            Common.MessageBox.ShowAndRedirect(this.Page, "操作成功", "OrderLogisticsList.aspx?orderid=" + OrderId);
        }
    }
}